package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceRelatedDeviceParamService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/pcbaDeviceRelatedPcbaDeviceParam")
public class PcbaDeviceRelatedPcbaDeviceParamController {

    @Autowired
    private PcbaDeviceRelatedDeviceParamService pcbaDeviceRelatedDeviceParamService;

    @PostMapping("/getAllByDeviceResourceId")
    public Result getAllByDeviceResourceId(Integer pcbaDeviceResourceId) {
        try {
            if (pcbaDeviceResourceId == null || "".equals(pcbaDeviceResourceId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceResourceId", "Miss Param pcbaDeviceResourceId", null);
            }
            return ResultUtil.success(pcbaDeviceRelatedDeviceParamService.getAllByDeviceResourceId(pcbaDeviceResourceId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    /*@PostMapping("/addOrUpdateDeviceRelatedParam")
    public Result addOrUpdateDeviceRelatedParam(PcbaDeviceRelatedDeviceParam pcbaDeviceRelatedDeviceParam, String mode){
        return pcbaDeviceRelatedDeviceParamService.addOrUpdateDeviceRelatedParam(pcbaDeviceRelatedDeviceParam, mode);
    }*/

    @PostMapping("/getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId")
    public Result getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(String pcbaDeviceParamkey, Integer pcbaDeviceResourceId) {
        return pcbaDeviceRelatedDeviceParamService.getPcbaDeviceRelatedDeviceParamByKeyAndDeviceResourceId(pcbaDeviceParamkey, pcbaDeviceResourceId);
    }

    @PostMapping("/getMinimumValueFromBaseKeys")
    public Result getMinimumValueFromBaseKeys(String bindDeviceParamKey, Integer pcbaDeviceResourceId) {
        return pcbaDeviceRelatedDeviceParamService.getMinimumValueFromBaseKeys(bindDeviceParamKey, pcbaDeviceResourceId);
    }
}
